package com.gitee.gen;

import com.gitee.gen.config.ConnectionHandler;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.AuditMessage;
import com.mybatisflex.core.audit.MessageCollector;
import org.noear.solon.Solon;
import org.noear.solon.annotation.Import;
import org.noear.solon.web.cors.CrossFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@Import(scanPackages = "cn.shoukaiseki")
public class App implements MessageCollector {

    private static final Logger logger = LoggerFactory.getLogger("mybatis-flex-sql");

    public static void main(String[] args) {
//        AuditManager.setAuditEnable(true);
        //设置 SQL 审计收集器
//        AuditManager.setMessageCollector(new App());
        Solon.start(App.class, args, app->{
            //例：增加全局处理（用过滤器模式）//对静态资源亦有效
            app.filter(-1, new CrossFilter().allowedOrigins("*")); //加-1 优先级更高

            app.after(new ConnectionHandler());
        });
    }


    @Override
    public void collect(AuditMessage auditMessage) {
            logger.debug(auditMessage.getFullSql());
            logger.debug("{}",auditMessage.getQueryParams());
            logger.debug("sql耗时{}ms", auditMessage.getElapsedTime());
    }
}
